package com.Model.Pojo;


import com.Model.Date.DateTime;
import com.Model.GetSqlSession;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Invest {
	private int id;
	private String invest_username;
	private String product_name;
	private double money;
	private String invest_date;
	private int month;
	private String end_time;
	private double after_money;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getInvest_username() {
		return invest_username;
	}

	public void setInvest_username(String invest_username) {
		this.invest_username = invest_username;
	}

	public String getProduct_name() {
		return product_name;
	}

	public void setProduct_name(String product_name) {
		this.product_name = product_name;
	}

	public double getMoney() {
		return money;
	}

	public void setMoney(double money) {
		this.money = money;
	}

	public String getInvest_date() {
		return invest_date;
	}

	public void setInvest_date(String invest_date) {
		this.invest_date = invest_date;
	}

	public int getMonth() {
		return month;
	}

	public void setMonth(int month) {
		this.month = month;
	}

	public String getEnd_time() {
		return end_time;
	}

	public void setEnd_time(String end_time) {
		this.end_time = end_time;
	}

	public double getAfter_money() {
		return after_money;
	}

	public void setAfter_money(double after_money) {
		this.after_money = after_money;
	}

	public void setUserInvest(HttpServletRequest request) throws IOException {
		HttpSession session = request.getSession(false);
		Users users = (Users) session.getAttribute("users");
		this.invest_username = users.getZhanghao();
		this.product_name = "劲松金融";//这个是作为参数传入的，现在先这样写，以后改
		this.money = Double.parseDouble(request.getParameter("touzijine"));
		DateTime dateTime = new DateTime();
		this.invest_date = dateTime.getSettime();
		this.month = Integer.parseInt(request.getParameter("month"));
		dateTime.setMonth(dateTime.getMonth()+this.month);
		this.end_time = dateTime.getSettime();
		this.after_money = this.money + this.money * this.month * 0.05;//计算的方法和利率都是要用参数的，现在先这样处理

		GetSqlSession getSqlSession = new GetSqlSession();//初始化获取sqlSession的对象
		SqlSession sqlSession = getSqlSession.getSqlSession();//获取sqlSession
		sqlSession.insert("addUsersInvest",this); //添加投资理财记录
		sqlSession.commit();
		sqlSession.close();//关闭连接
	}

	public List<Invest> getInvestListByName(String name) throws IOException {
		List<Invest> list ;
		GetSqlSession getSqlSession = new GetSqlSession();//初始化获取sqlSession的对象
		SqlSession sqlSession = getSqlSession.getSqlSession();//获取sqlSession
		list = sqlSession.selectList("getInvestListByName",name); //添加投资理财记录
		sqlSession.commit();
		sqlSession.close();//关闭连接
		return list;
	}
}
